package ch.tiktak.games.powersudoku;

import au.com.bytecode.opencsv.CSVReader;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

public class CSVGridReader {

    public List<int[]> getEntries() {
        return entries;
    }

    private List<int[]> entries;

    public CSVGridReader(File csvFile) throws IOException {
        CSVReader csvReader = new CSVReader(new FileReader(csvFile));
        List<String[]> stringEntries = csvReader.readAll();

        entries = new LinkedList<int[]>();
        for (String[] s : stringEntries) {
            int[] result = new int[s.length];
            for (int i = 0; i < s.length; i++) {
                result[i] = (s[i].equals("")) ? -1 : Integer.valueOf(s[i]);
            }
            entries.add(result);
        }
    }

    public CSVGridReader(String name) throws IOException {
        this(new File(name));
    }

    public static void main(String[] args) {
        try {
            CSVGridReader reader = new CSVGridReader("/home/mathieu/dev/test/tinytools/sudoku-solver/src/grid2.csv");
            List<int[]> myEntries = reader.getEntries();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
